﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using BBInterfaceNET.ViewModels;
using BBInterfaceNET.Views;
using System.Windows;

namespace BBInterfaceNET.Services
{
    public class InteractionService:IInteractionService
    {
        public void ShowMessageBox(string caption, string text, Action<bool> callback)
        {
            MessageBoxResult res = MessageBox.Show(text, caption, MessageBoxButton.OK);
            callback(res == MessageBoxResult.OK ? true : false);
        }
        public string OpenFile(bool isProject)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (isProject)
                dlg.Filter = "Project File (*.bbpx)|*.bbpx";

            bool? res = dlg.ShowDialog();
            if (res.HasValue && res.Value)
                return dlg.FileName;
            else
                return null;
        }


        public string GetDirectory()
        {
            System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Forms.DialogResult res = dlg.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                return dlg.SelectedPath;
            }
            return null;
        }


        public void ShowNewProjectView(Action<ViewModels.NewProjectViewModel> callback)
        {
            NewProjectViewModel vm = new NewProjectViewModel(this);
            vm.Title = "New Project";
            vm.CreateProjectDirectory = true;

            NewProjectView view = new NewProjectView();
            view.DataContext = vm;
            view.Closed += (s, e) => {
                vm.Result = view.DialogResult;
                callback(vm);
            };
            view.ShowDialog();
        }

        public void ShowConfirmationDialog(string caption, string text, Action<bool?> callback)
        {
            MessageBoxResult res = MessageBox.Show(text, caption, MessageBoxButton.YesNoCancel);
            bool? result = null;
            if (res == MessageBoxResult.Yes)
                result = true;
            else if (res == MessageBoxResult.No)
                result = false;
            callback(result);
        }
    }
}
